using log4net;
using Quartz;
using Quartz.Impl;
using Topshelf;

namespace SmartLink.Job
{
    public class ServiceRunner : ServiceControl, ServiceSuspend
    {
        readonly ILog _log = LogManager.GetLogger(typeof(ServiceRunner));
        private readonly IScheduler _scheduler;

        public ServiceRunner(IScheduler scheduler)
        {
            _scheduler = scheduler;
        }

        public bool Start(HostControl hostControl)
        {
            _log.Info("Service is Starting....");
            _scheduler.Start();
            return true;
        }

        public bool Stop(HostControl hostControl)
        {
            _log.Info("Service is Stoping....");
            _scheduler.Shutdown(false);
            return true;
        }

        public bool Continue(HostControl hostControl)
        {
            _log.Info("Service is Continueing....");
            _scheduler.ResumeAll();
            return true;
        }

        public bool Pause(HostControl hostControl)
        {
            _log.Info("Service is Pauseing....");
            _scheduler.PauseAll();
            return true;
        }
    }
}
